package com.quanyan.riding.web;

import com.github.ltsopensource.core.json.JSON;
import com.quanyan.api.APIResponse;
import com.quanyan.common.utils.StringUtil;
import com.quanyan.riding.entity.vo.req.ReqRidingRecord;
import com.quanyan.riding.entity.vo.req.UserInfo;
import com.quanyan.riding.entity.vo.resp.RespRidingFirstPage;
import com.quanyan.riding.entity.vo.resp.RespRidingSideUserInfo;
import com.quanyan.riding.service.RidingUserService;
import com.quanyan.riding.util.RunRidingEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author xian-guo
 * @email 498152332@qq.com
 * @date 2016/8/29.
 */
@RestController
@RequestMapping(value = "api/riding")
public class RidingUserController {

    private static final Logger LOGGER = LoggerFactory.getLogger(RidingUserController.class);

    /**
     * 用户
     */
    @Autowired
    private RidingUserService ridingUserService;

    /**
     * 用户登录
     * @param userInfo
     * @return
     */
    @RequestMapping(value = "userLogin",method = RequestMethod.POST)
    public APIResponse<RespRidingFirstPage> userLogin(@RequestBody(required = true) UserInfo userInfo){
        LOGGER.debug("--------------->>>>"+JSON.toJSONString(userInfo));
        if (StringUtil.isBlankOrNull(userInfo.getUserId()) || StringUtil.isBlankOrNull(userInfo.getPhotoUrl()) ||StringUtil.isBlankOrNull(userInfo.getUserNick())
                 || null == userInfo.getGender()){
            return APIResponse.returnFail(RunRidingEnum.PARAMETER_NOT_ALLOW_NULL);
        }
        return ridingUserService.isUserLogin(userInfo);
    }

    /**
     * 侧边栏显示用户等级信息
     * @param paramMap
     * @return
     */
    @RequestMapping(value = "sideUserLevelInfo",method = RequestMethod.POST)
    public APIResponse<RespRidingSideUserInfo> getSideUserLevelInfo(@RequestBody(required = true) Map<String,Object> paramMap){
        LOGGER.debug("------------>>>>>>>>>"+JSON.toJSONString(paramMap));
        String userId= (String) paramMap.get("userId");
        if(StringUtil.isBlankOrNull(userId)){
            return APIResponse.returnFail(RunRidingEnum.PARAMETER_NOT_ALLOW_NULL);
        }
        return ridingUserService.getSideUserLevelInfo(userId);
    }

    /**
     * 路书上用户个人主页
     * @param reqRidingRecord
     * @return
     */
    @RequestMapping(value = "ridingPathUserDetailMsg",method = RequestMethod.POST)
    public APIResponse<Map<String,Object>> getRidingPathUserDetailMsg(@RequestBody(required = true) ReqRidingRecord reqRidingRecord){
        LOGGER.debug("------------>>>>>>>>>"+JSON.toJSONString(reqRidingRecord));
        if(StringUtil.isBlankOrNull(reqRidingRecord.getUserId()) || null == reqRidingRecord.getPageNum() || null == reqRidingRecord.getPageSize()){
            return APIResponse.returnFail(RunRidingEnum.PARAMETER_NOT_ALLOW_NULL);
        }
        return ridingUserService.getRidingPathUserDetailMsg(reqRidingRecord);
    }

}
